package router

import (
	"github.com/e421083458/golang_common/lib"
	"github.com/gin-gonic/gin"
	"github.com/swaggo/files"
	"github.com/swaggo/gin-swagger"
	"tino_manager/controller"
	"tino_manager/docs"
	"tino_manager/middleware"
)

func InitRouter(middlewares ...gin.HandlerFunc) *gin.Engine {
	docs.SwaggerInfo.Title = lib.GetStringConf("base.swagger.title")
	docs.SwaggerInfo.Description = lib.GetStringConf("base.swagger.desc")
	docs.SwaggerInfo.Version = "1.0"
	docs.SwaggerInfo.Host = lib.GetStringConf("base.swagger.host")
	docs.SwaggerInfo.BasePath = lib.GetStringConf("base.swagger.base_path")
	docs.SwaggerInfo.Schemes = []string{"http", "https"}

	router := gin.Default()
	router.Use(middlewares...)
	router.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	//用户 user
	user := router.Group("/user")
	user.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
	)
	{
		controller.UserRegister(user)
	}
	//管理员 manager
	manager := router.Group("/manager")
	manager.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
	)
	{
		controller.ManagerRegister(manager)
	}

	//字典 dicData
	dicData := router.Group("/dic_data")
	dicData.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
	)
	{
		controller.DicDataRegister(dicData)
	}

	//场地 site
	site := router.Group("/site")
	site.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
		middleware.WeAppMiddleware(),
	)
	{
		controller.SiteRegister(site)
	}

	//通知 notice
	notice := router.Group("/notice")
	notice.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
	)
	{
		controller.NoticeRegister(notice)
	}
	//活动 activity
	activity := router.Group("/activity")
	activity.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
	)
	{
		controller.ActivityRegister(activity)
	}
	//reservation 预约
	reservation := router.Group("/reservation")
	reservation.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
	)
	{
		controller.ReservationRegister(reservation)
	}
	//collect 收藏
	collect := router.Group("/collect")
	collect.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
		middleware.WeAppMiddleware(),
	)
	{
		controller.CollectRegister(collect)
	}
	//browse 浏览记录
	browse := router.Group("/browse")
	browse.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
		middleware.WeAppMiddleware(),
	)
	{
		controller.BrowseRegister(browse)
	}
	//data 统计
	data := router.Group("/data")
	data.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
		middleware.WeAppMiddleware(),
	)
	{
		controller.DataRegister(data)
	}
	//信息设置
	contract := router.Group("/contract")
	contract.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
		middleware.WeAppMiddleware(),
	)
	{
		controller.ContractRegister(contract)
	}
	//swiper
	swiper := router.Group("/swiper")
	swiper.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
		middleware.WeAppMiddleware(),
	)
	{
		controller.SwiperRegister(swiper)
	}
	//oss
	oss := router.Group("/oss")
	oss.Use(middleware.RecoveryMiddleware(),
		middleware.RequestLog(),
		middleware.TranslationMiddleware(),
	)
	{
		controller.OssRegister(oss)
	}
	return router
}
